from django.contrib import admin
from django.utils.html import format_html

# Register your models here.
from .models import *


class UserAdmin(admin.ModelAdmin):
    list_display = ('id','head_img','name','aname', 'gender', 'age','aphone','email', 'addr','view_link')
    ordering = ('id',)

    def view_link(self,obj):
        # 'obj' 是当前的 Order 实例
        url = f'/chat/?group={obj.id}&user=0'
        return format_html('<a href="{}" target="_blank">联系客户</a>', url)
    view_link.short_description = '操作'

    def head_img(self, obj):

        return format_html('<img src="/{}"style="width:100px;height:auto;">', obj.head)

    head_img.short_description = '头像'  # 修改标题以反映内容

admin.site.register(User, UserAdmin)